<template>
  <div class="course-list flex-r-start flex-wrap" style="width: 100%;">
    <div
      class="item"
      style="box-sizing: border-box;padding: 20px;"
      v-for="item in courseList"
      :style="{flexBasis: basis}"
      :key="item.courseId"
      @click="toDetail(item.courseId)"
    >
      <el-card>
        <div class="img-container">
          <el-image style="width: 100%; height: 155px" :src="item.courseCover">
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
          <div class="process" v-show="showProgress">
            <el-progress
              :text-inside="true"
              :stroke-width="20"
              :percentage="(item.courseDegree&&item.courseDegree !='NaN')?Number(item.courseDegree.toFixed(1)):0"
              :color="customColorMethod"
            ></el-progress>
          </div>
        </div>
        <div class="pl10 font-weight font20 mb5" style="color: #212121;">课程名称：{{item.courseName}}</div>
        <div class="pl10 mb5 grey">开课时间：{{item.beginData}}</div>
        <div class="pl10 grey">结课时间：{{item.endData}}</div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "courseCard",
  props: {
    courseList: {
      type: Array,
      default: () => []
    },
    basis: {
      type: String,
      default: "25%"
    },
    showProgress: Boolean
  },
  methods: {
    toDetail(id) {
      this.$emit("click", id);
    },
    /** 进度颜色 */
    customColorMethod(percentage) {
      if (percentage < 20.0) {
        return "#F56C6C";
      } else if (percentage < 60.0) {
        return "#E6A23C";
      } else if (percentage < 80.0) {
        return "#409EFF";
      } else {
        return "#67C23A";
      }
    }
  }
};
</script>

<style>
.course-list .el-card {
  border-radius: 10px !important;
  /* margin-right: 40px;
  margin-top: 40px; */
  cursor: pointer;
}
.course-list .el-card .el-card__body {
  padding: 0 0 20px 0 !important;
}
.img-container {
  position: relative;
}
.img-container .process {
  position: absolute;
  top: 135px;
  width: 100%;
  margin: 0 auto;
}
.process .el-progress-bar__outer {
  border-radius: 0 !important;
}
.process .el-progress-bar__outer,
.el-progress-bar__inner {
  border-radius: 0 !important;
}
.process .el-progress-bar__innerText {
  color: #212121 !important;
}

.image-slot {
  background-color: #f8f8f8;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 32px;
}
</style>
